package com.joeshing.security.resourcedetails;

import java.util.Collection;

import org.springframework.security.access.ConfigAttribute;
import org.springframework.util.Assert;

public class Resource implements ResourceDetails {
	
	private static final long serialVersionUID = 4640497640533200574L;

	private String name;

	private String type;
	
	private Collection<ConfigAttribute> attributes;

	public Resource(String name, String type,Collection<ConfigAttribute> attributes) {
		Assert.notNull(name,"Cannot pass null or empty values to resource Name");
		Assert.notNull(type,"Cannot pass null or empty values to resource Type");
		Assert.notNull(attributes,"Cannot pass null or empty values to resource Attributes");
		this.name = name;
		this.type = type;
		this.attributes = attributes;
	}

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public String getType() {
		return type;
	}

	public void setType(String type) {
		this.type = type;
	}

	public Collection<ConfigAttribute> getAttributes() {
		return attributes;
	}

	public void setAttributes(Collection<ConfigAttribute> attributes) {
		this.attributes = attributes;
	}

	@Override
	public int hashCode() {
		final int prime = 31;
		int result = 1;
		result = prime * result
				+ ((attributes == null) ? 0 : attributes.hashCode());
		result = prime * result + ((name == null) ? 0 : name.hashCode());
		result = prime * result + ((type == null) ? 0 : type.hashCode());
		return result;
	}

	@Override
	public boolean equals(Object obj) {
		if (this == obj)
			return true;
		if (obj == null)
			return false;
		if (getClass() != obj.getClass())
			return false;
		Resource other = (Resource) obj;
		if (attributes == null) {
			if (other.attributes != null)
				return false;
		} else if (!attributes.equals(other.attributes))
			return false;
		if (name == null) {
			if (other.name != null)
				return false;
		} else if (!name.equals(other.name))
			return false;
		if (type == null) {
			if (other.type != null)
				return false;
		} else if (!type.equals(other.type))
			return false;
		return true;
	}

}

